<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use App\Http\Controllers\Admin\ItemDataController;
use DB;
/* 修改项目更新样品结果和时间及其历史数据 */
class AfterEditItemDataJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $params;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($params)
    {
        $this->params = $params;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $params = $this->params;
        info(' AfterEditItemData ,params:'.json_encode($params));
        $sample_info_id = $params['sample_info_id'];
        $itemDataController = new ItemDataController();
        $itemDataController->updateJieLun($sample_info_id); //更新 a_sample_info 表的 结论
        $itemDataController->updateTester($sample_info_id); //更新 a_sample_info 表的 检验人员
        $itemDataController->updateTestTime_NextTime($sample_info_id); //更新 a_sample_info 表的 试验时间 和 下次试验时间
        $inputLogs = isset($params['input_data_logs'])? $params['input_data_logs']: [];
        if($inputLogs){
            DB::table('a_input_data_log')->insert($params['input_data_logs']);
        }
    }
}
